home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 16 windows forms / windowsformsdemo / dialoginheritedform.vb < prev    next >
Encoding:
Text File  |  2002-03-20  |  3.4 KB  |  102 lines

  1.  
  2.  
  3. Public Class DialogInheritedForm
  4.     Inherits WindowsFormsDemo.DialogBaseForm
  5.  
  6. #Region " Windows Form Designer generated code "
  7.  
  8.     Public Sub New()
  9.         MyBase.New()
  10.  
  11.         'This call is required by the Windows Form Designer.
  12.         InitializeComponent()
  13.  
  14.         'Add any initialization after the InitializeComponent() call
  15.  
  16.     End Sub
  17.  
  18.     'Form overrides dispose to clean up the component list.
  19.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  20.         If disposing Then
  21.             If Not (components Is Nothing) Then
  22.                 components.Dispose()
  23.             End If
  24.         End If
  25.         MyBase.Dispose(disposing)
  26.     End Sub
  27.     Friend WithEvents chkUpperCase As System.Windows.Forms.CheckBox
  28.  
  29.     'Required by the Windows Form Designer
  30.     Private components As System.ComponentModel.Container
  31.  
  32.     'NOTE: The following procedure is required by the Windows Form Designer
  33.     'It can be modified using the Windows Form Designer.  
  34.     'Do not modify it using the code editor.
  35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  36.         Me.chkUpperCase = New System.Windows.Forms.CheckBox()
  37.         Me.SuspendLayout()
  38.         '
  39.         'txtValue
  40.         '
  41.         Me.txtValue.Visible = True
  42.         '
  43.         'btnCancel
  44.         '
  45.         Me.btnCancel.Visible = True
  46.         '
  47.         'btnOK
  48.         '
  49.         Me.btnOK.Enabled = False
  50.         Me.btnOK.Visible = True
  51.         '
  52.         'lblMessage
  53.         '
  54.         Me.lblMessage.Text = "Type a string without any spaces in it"
  55.         Me.lblMessage.Visible = True
  56.         '
  57.         'chkUpperCase
  58.         '
  59.         Me.chkUpperCase.Location = New System.Drawing.Point(56, 96)
  60.         Me.chkUpperCase.Name = "chkUpperCase"
  61.         Me.chkUpperCase.Size = New System.Drawing.Size(208, 32)
  62.         Me.chkUpperCase.TabIndex = 4
  63.         Me.chkUpperCase.Text = "Convert to UpperCase"
  64.         '
  65.         'DialogInheritedForm
  66.         '
  67.         Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
  68.         Me.ClientSize = New System.Drawing.Size(512, 149)
  69.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtValue, Me.btnCancel, Me.btnOK, Me.lblMessage, Me.chkUpperCase})
  70.         Me.Name = "DialogInheritedForm"
  71.         Me.Text = "DialogInheritedForm"
  72.         Me.ResumeLayout(False)
  73.  
  74.     End Sub
  75.  
  76. #End Region
  77.  
  78.     ' in this inherited form we enable the OK button only after the user enters a string
  79.     Private Sub txtValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtValue.TextChanged
  80.         Me.btnOK.Enabled = (txtValue.Text <> "")
  81.     End Sub
  82.  
  83.     ' Convert to uppercase if so requested 
  84.     Private Sub txtValue_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles txtValue.KeyPress
  85.         If Char.IsLower(e.KeyChar) AndAlso chkUpperCase.Checked Then
  86.             txtValue.SelectedText = Char.ToUpper(e.KeyChar)
  87.             e.Handled = True
  88.         End If
  89.     End Sub
  90.  
  91.     ' in this inherited form we reject strings that contain space
  92.     Protected Overrides Sub OnOkClick()
  93.         ' call the base form procedure only if the string doesn't contain space
  94.         If InStr(txtValue.Text, " ") = 0 Then
  95.             MyBase.OnOkClick()
  96.         Else
  97.             MessageBox.Show("Please remove all spaces from this string", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  98.         End If
  99.     End Sub
  100.  
  101. End Class
  102.